Ext.define('Lms.rms.SoftwareInfoDialog',{
	openWindow : function(config) {
		Ext.apply(this, config);
		this.isEditableMode = false; 
		var title = LocaleUtil.getMessage('rms.label.software');
		if(typeof(config) != 'undefined'){
			title += LocaleUtil.getMessage('rms.label.detail');
			this.isEditableMode = true;
		}else{
			title = LocaleUtil.getMessage('rms.label.reg');
		}
		this.dialog = Common.openDialog(title, 500, null, [{
			text : (this.isEditableMode)?LocaleUtil.getMessage('update'):LocaleUtil.getMessage('reg'),
			scope : this,
			hidden : (loginAuth == 'N')?true:false,
			handler : function(){
				if(!this.form.isValid()) return;
				Common.confirm(LocaleUtil.getMessage('confirm'),LocaleUtil.getMessage('rms.msg.doYouWantToSave'),function(btn){
					if(btn == 'yes'){
						var url;
						if(this.isEditableMode){
							//수정 logic
							url = 'software/update.do';
						}else{
							//등록 logic
							url = 'software/create.do';
						}
						this.form.submit({
							url : url,
							params : this.form.getForm().getValues(),
							waitMsg: LocaleUtil.getMessage('rms.msg.waitToSaving'),
							scope : this,
							success : function(form, action){
								this.dialog.close();
								Ext.getCmp('SoftwareMgmPanel').getStore().reload();
							},
							failure : Common.failureMessageSubmit
						});
					}
				},this);
			}
		},{
			text : LocaleUtil.getMessage('close'),
			cls : 'blue_button',
			scope : this,
			handler : function() {
				this.dialog.close();
			}
		}]);
		this.dialog.resizable = true;
//		this.dialog.iconCls = 'detail_search';
		this.dialog.add(this.getForm());
		this.dialog.show();
		if(this.isEditableMode){
			this.getData();
		}
	},
	
	getData : function(){
		this.form.load({
			url : 'software/findInfo.do',
			params : {
				id : this.id
			}
		});		
	},
	
	getForm : function(){
		this.form = Ext.widget('form',{
		    frame : false,
		    border : false,
		    region : 'north',
		    bodyPadding: '5 5 0',
	        defaults: {anchor: '100%'},
	        defaultType: 'textfield',
	        fieldDefaults: {
	        	labelAlign : 'right',
                labelWidth: 120,
                msgTarget : 'side'
            },
	        items :[{
	        		xtype : 'hiddenfield',
	        		name : 'id'
	        	},{            	
                    fieldLabel: LocaleUtil.getMessage('rms.label.swName'),
                    name: 'name',
                    allowBlank : false,
                    readOnly : false
                },{
                	xtype : 'combobox',
                	store : ['CONTENT','AGENT'],
                    fieldLabel: LocaleUtil.getMessage('rms.label.type'),
                    editable: false,
                    forceSelection: true,
                    name: 'type',
                    allowBlank : false,
                    readOnly : false
                },{
                	fieldLabel : LocaleUtil.getMessage('rms.label.version'),
                	name : 'fileVer',
                	allowBlank : false
                },{
                	xtype : 'textarea',
                	fieldLabel: LocaleUtil.getMessage('rms.label.description'),
                    name: 'description',
                    grow      : true,
                    readOnly : false
                },{
                	xtype : 'filefield',                		
                    fieldLabel: LocaleUtil.getMessage('rms.label.fileReg'),
                    name: 'softwareFile',
                    allowBlank : this.isEditableMode? true : false,
                    readOnly : false
                }
            ]      
		});
		
		return this.form;
	}
});